package com.atguigu.tingshu.user.client;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import com.atguigu.tingshu.user.client.impl.UserDegradeFeignClient;
import com.atguigu.tingshu.user.config.FeignClientConfig;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户模块远程调用API接口
 * </p>
 *
 * @author atguigu
 */
@FeignClient(value = "service-user", path = "api/user", fallback = UserDegradeFeignClient.class, configuration = FeignClientConfig.class)
public interface UserFeignClient {

    /**
     * 根据用户ID查询用户信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/userInfo/getUserInfoVo/{userId}")
    Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId);

    /**
     * 获取用户声音列表付费情况
     *
     * @param userId                    用户ID
     * @param albumId                   专辑ID
     * @param needCheckBuyStateTrackIds 需要检查购买状态的声音ID列表
     * @return 声音ID与付费状态的映射，1表示已购买，0表示未购买
     */
    @PostMapping("/userInfo/userIsPaidTrack/{userId}/{albumId}")
    Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable Long userId,
            @PathVariable Long albumId,
            @RequestBody List<Long> needCheckBuyStateTrackIds);

    /**
     * 根据VIP配置ID查询VIP套餐详情
     *
     * @param id VIP配置ID
     * @return VIP配置详情
     */
    @GetMapping("/vipServiceConfig/getVipServiceConfig/{id}")
    Result<VipServiceConfig> getVipServiceConfig(@PathVariable Long id);

    /**
     * 判断用户是否购买过专辑
     *
     * @param albumId 专辑ID
     * @return true-已购买，false-未购买
     */
    @GetMapping("/userInfo/isPaidAlbum/{albumId}")
    Result<Boolean> isPaidAlbum(@PathVariable Long albumId);

    /**
     * 判断用户是否购买过声音列表
     *
     * @param trackIdList 声音ID列表
     * @return true-至少购买过一个声音，false-没有购买过任何声音
     */
    @PostMapping("/userInfo/isPaidTrack")
    Result<Boolean> isPaidTrack(@RequestBody List<Long> trackIdList);

    /**
     * 保存用户购买记录
     *
     * @param userPaidRecordVo 用户购买记录VO
     * @return 成功或失败
     */
    @PostMapping("/userInfo/savePaidRecord")
    Result<Void> savePaidRecord(@RequestBody UserPaidRecordVo userPaidRecordVo);
}
